<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1999-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Error and Warning Options (The GNU Fortran Compiler)</title>

<meta name="description" content="Error and Warning Options (The GNU Fortran Compiler)">
<meta name="keywords" content="Error and Warning Options (The GNU Fortran Compiler)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Invoking-GNU-Fortran.html#Invoking-GNU-Fortran" rel="up" title="Invoking GNU Fortran">
<link href="Debugging-Options.html#Debugging-Options" rel="next" title="Debugging Options">
<link href="Preprocessing-Options.html#Preprocessing-Options" rel="prev" title="Preprocessing Options">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<a name="Error-and-Warning-Options"></a>
<div class="header">
<p>
Next: <a href="Debugging-Options.html#Debugging-Options" accesskey="n" rel="next">Debugging Options</a>, Previous: <a href="Preprocessing-Options.html#Preprocessing-Options" accesskey="p" rel="prev">Preprocessing Options</a>, Up: <a href="Invoking-GNU-Fortran.html#Invoking-GNU-Fortran" accesskey="u" rel="up">Invoking GNU Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Options-to-request-or-suppress-errors-and-warnings"></a>
<h3 class="section">2.4 Options to request or suppress errors and warnings</h3>
<a name="index-options_002c-warnings"></a>
<a name="index-options_002c-errors"></a>
<a name="index-warnings_002c-suppressing"></a>
<a name="index-messages_002c-error"></a>
<a name="index-messages_002c-warning"></a>
<a name="index-suppressing-warnings"></a>

<p>Errors are diagnostic messages that report that the GNU Fortran compiler
cannot compile the relevant piece of source code.  The compiler will
continue to process the program in an attempt to report further errors
to aid in debugging, but will not produce any compiled output.  
</p>
<p>Warnings are diagnostic messages that report constructions which
are not inherently erroneous but which are risky or suggest there is
likely to be a bug in the program.  Unless <samp>-Werror</samp> is specified,
they do not prevent compilation of the program.
</p>
<p>You can request many specific warnings with options beginning <samp>-W</samp>,
for example <samp>-Wimplicit</samp> to request warnings on implicit
declarations.  Each of these specific warning options also has a
negative form beginning <samp>-Wno-</samp> to turn off warnings;
for example, <samp>-Wno-implicit</samp>.  This manual lists only one of the
two forms, whichever is not the default.
</p>
<p>These options control the amount and kinds of errors and warnings produced
by GNU Fortran:
</p>
<dl compact="compact">
<dd><a name="index-fmax_002derrors_003dn"></a>
<a name="index-errors_002c-limiting"></a>
</dd>
<dt><code>-fmax-errors=<var>n</var></code></dt>
<dd><p>Limits the maximum number of error messages to <var>n</var>, at which point
GNU Fortran bails out rather than attempting to continue processing the
source code.  If <var>n</var> is 0, there is no limit on the number of error
messages produced.
</p>
<a name="index-fsyntax_002donly"></a>
<a name="index-syntax-checking"></a>
</dd>
<dt><code>-fsyntax-only</code></dt>
<dd><p>Check the code for syntax errors, but do not actually compile it.  This
will generate module files for each module present in the code, but no
other output file.
</p>
<a name="index-pedantic"></a>
<a name="index-Wpedantic"></a>
</dd>
<dt><code>-Wpedantic</code></dt>
<dt><code>-pedantic</code></dt>
<dd><p>Issue warnings for uses of extensions to Fortran.
<samp>-pedantic</samp> also applies to C-language constructs where they
occur in GNU Fortran source files, such as use of &lsquo;<samp>\e</samp>&rsquo; in a
character constant within a directive like <code>#include</code>.
</p>
<p>Valid Fortran programs should compile properly with or without
this option.
However, without this option, certain GNU extensions and traditional
Fortran features are supported as well.
With this option, many of them are rejected.
</p>
<p>Some users try to use <samp>-pedantic</samp> to check programs for conformance.
They soon find that it does not do quite what they want&mdash;it finds some
nonstandard practices, but not all.
However, improvements to GNU Fortran in this area are welcome.
</p>
<p>This should be used in conjunction with <samp>-std=f95</samp>,
<samp>-std=f2003</samp>, <samp>-std=f2008</samp> or <samp>-std=f2018</samp>.
</p>
<a name="index-pedantic_002derrors"></a>
</dd>
<dt><code>-pedantic-errors</code></dt>
<dd><p>Like <samp>-pedantic</samp>, except that errors are produced rather than
warnings.
</p>
<a name="index-Wall"></a>
<a name="index-all-warnings"></a>
<a name="index-warnings_002c-all"></a>
</dd>
<dt><code>-Wall</code></dt>
<dd><p>Enables commonly used warning options pertaining to usage that
we recommend avoiding and that we believe are easy to avoid.
This currently includes <samp>-Waliasing</samp>, <samp>-Wampersand</samp>,
<samp>-Wconversion</samp>, <samp>-Wsurprising</samp>, <samp>-Wc-binding-type</samp>,
<samp>-Wintrinsics-std</samp>, <samp>-Wtabs</samp>, <samp>-Wintrinsic-shadow</samp>,
<samp>-Wline-truncation</samp>, <samp>-Wtarget-lifetime</samp>,
<samp>-Winteger-division</samp>, <samp>-Wreal-q-constant</samp>, <samp>-Wunused</samp>
and <samp>-Wundefined-do-loop</samp>.
</p>
<a name="index-Waliasing"></a>
<a name="index-aliasing"></a>
<a name="index-warnings_002c-aliasing"></a>
</dd>
<dt><code>-Waliasing</code></dt>
<dd><p>Warn about possible aliasing of dummy arguments. Specifically, it warns
if the same actual argument is associated with a dummy argument with
<code>INTENT(IN)</code> and a dummy argument with <code>INTENT(OUT)</code> in a call
with an explicit interface.
</p>
<p>The following example will trigger the warning.
</p><div class="smallexample">
<pre class="smallexample">  interface
    subroutine bar(a,b)
      integer, intent(in) :: a
      integer, intent(out) :: b
    end subroutine
  end interface
  integer :: a

  call bar(a,a)
</pre></div>

<a name="index-Wampersand"></a>
<a name="index-warnings_002c-ampersand"></a>
<a name="index-_0026"></a>
</dd>
<dt><code>-Wampersand</code></dt>
<dd><p>Warn about missing ampersand in continued character constants. The
warning is given with <samp>-Wampersand</samp>, <samp>-pedantic</samp>,
<samp>-std=f95</samp>, <samp>-std=f2003</samp>, <samp>-std=f2008</samp> and
<samp>-std=f2018</samp>. Note: With no ampersand given in a continued
character constant, GNU Fortran assumes continuation at the first
non-comment, non-whitespace character after the ampersand that
initiated the continuation.
</p>
<a name="index-Warray_002dtemporaries"></a>
<a name="index-warnings_002c-array-temporaries"></a>
</dd>
<dt><code>-Warray-temporaries</code></dt>
<dd><p>Warn about array temporaries generated by the compiler.  The information
generated by this warning is sometimes useful in optimization, in order to
avoid such temporaries.
</p>
<a name="index-Wc_002dbinding_002dtype"></a>
<a name="index-warning_002c-C-binding-type"></a>
</dd>
<dt><code>-Wc-binding-type</code></dt>
<dd><p>Warn if the a variable might not be C interoperable.  In particular, warn if 
the variable has been declared using an intrinsic type with default kind
instead of using a kind parameter defined for C interoperability in the
intrinsic <code>ISO_C_Binding</code> module.  This option is implied by
<samp>-Wall</samp>.
</p>
<a name="index-Wcharacter_002dtruncation"></a>
<a name="index-warnings_002c-character-truncation"></a>
</dd>
<dt><code>-Wcharacter-truncation</code></dt>
<dd><p>Warn when a character assignment will truncate the assigned string.
</p>
<a name="index-Wline_002dtruncation"></a>
<a name="index-warnings_002c-line-truncation"></a>
</dd>
<dt><code>-Wline-truncation</code></dt>
<dd><p>Warn when a source code line will be truncated.  This option is
implied by <samp>-Wall</samp>.  For free-form source code, the default is
<samp>-Werror=line-truncation</samp> such that truncations are reported as
error.
</p>
<a name="index-Wconversion"></a>
<a name="index-warnings_002c-conversion"></a>
<a name="index-conversion"></a>
</dd>
<dt><code>-Wconversion</code></dt>
<dd><p>Warn about implicit conversions that are likely to change the value of 
the expression after conversion. Implied by <samp>-Wall</samp>.
</p>
<a name="index-Wconversion_002dextra"></a>
<a name="index-warnings_002c-conversion-1"></a>
<a name="index-conversion-1"></a>
</dd>
<dt><code>-Wconversion-extra</code></dt>
<dd><p>Warn about implicit conversions between different types and kinds. This
option does <em>not</em> imply <samp>-Wconversion</samp>.
</p>
<a name="index-Wextra"></a>
<a name="index-extra-warnings"></a>
<a name="index-warnings_002c-extra"></a>
</dd>
<dt><code>-Wextra</code></dt>
<dd><p>Enables some warning options for usages of language features which
may be problematic. This currently includes <samp>-Wcompare-reals</samp>,
<samp>-Wunused-parameter</samp> and <samp>-Wdo-subscript</samp>.
</p>
<a name="index-Wfrontend_002dloop_002dinterchange"></a>
<a name="index-warnings_002c-loop-interchange"></a>
<a name="index-loop-interchange_002c-warning"></a>
</dd>
<dt><code>-Wfrontend-loop-interchange</code></dt>
<dd><p>Warn when using <samp>-ffrontend-loop-interchange</samp> for performing loop
interchanges.
</p>
<a name="index-Wimplicit_002dinterface"></a>
<a name="index-warnings_002c-implicit-interface"></a>
</dd>
<dt><code>-Wimplicit-interface</code></dt>
<dd><p>Warn if a procedure is called without an explicit interface.
Note this only checks that an explicit interface is present.  It does not
check that the declared interfaces are consistent across program units.
</p>
<a name="index-Wimplicit_002dprocedure"></a>
<a name="index-warnings_002c-implicit-procedure"></a>
</dd>
<dt><code>-Wimplicit-procedure</code></dt>
<dd><p>Warn if a procedure is called that has neither an explicit interface
nor has been declared as <code>EXTERNAL</code>.
</p>
<a name="index-Winteger_002ddivision"></a>
<a name="index-warnings_002c-integer-division"></a>
<a name="index-warnings_002c-division-of-integers"></a>
</dd>
<dt><code>-Winteger-division</code></dt>
<dd><p>Warn if a constant integer division truncates its result.
As an example, 3/5 evaluates to 0.
</p>
<a name="index-Wintrinsics_002dstd"></a>
<a name="index-warnings_002c-non_002dstandard-intrinsics"></a>
<a name="index-warnings_002c-intrinsics-of-other-standards"></a>
</dd>
<dt><code>-Wintrinsics-std</code></dt>
<dd><p>Warn if <code>gfortran</code> finds a procedure named like an intrinsic not
available in the currently selected standard (with <samp>-std</samp>) and treats
it as <code>EXTERNAL</code> procedure because of this.  <samp>-fall-intrinsics</samp> can
be used to never trigger this behavior and always link to the intrinsic
regardless of the selected standard.
</p>
<a name="index-Woverwrite_002drecursive"></a>
<a name="index-warnings_002c-overwrite-recursive"></a>
</dd>
<dt><code>-Wno-overwrite-recursive</code></dt>
<dd><p>Do not warn when <samp>-fno-automatic</samp> is used with <samp>-frecursive</samp>. Recursion
will be broken if the relevant local variables do not have the attribute
<code>AUTOMATIC</code> explicitly declared. This option can be used to suppress the warning
when it is known that recursion is not broken. Useful for build environments that use
<samp>-Werror</samp>.
</p>
<a name="index-Wreal_002dq_002dconstant"></a>
<a name="index-warnings_002c-q-exponent_002dletter"></a>
</dd>
<dt><code>-Wreal-q-constant</code></dt>
<dd><p>Produce a warning if a real-literal-constant contains a <code>q</code>
exponent-letter.
</p>
<a name="index-Wsurprising"></a>
<a name="index-warnings_002c-suspicious-code"></a>
</dd>
<dt><code>-Wsurprising</code></dt>
<dd><p>Produce a warning when &ldquo;suspicious&rdquo; code constructs are encountered.
While technically legal these usually indicate that an error has been made.
</p>
<p>This currently produces a warning under the following circumstances:
</p>
<ul>
<li> An INTEGER SELECT construct has a CASE that can never be matched as its
lower value is greater than its upper value.

</li><li> A LOGICAL SELECT construct has three CASE statements.

</li><li> A TRANSFER specifies a source that is shorter than the destination.

</li><li> The type of a function result is declared more than once with the same type.  If
<samp>-pedantic</samp> or standard-conforming mode is enabled, this is an error.

</li><li> A <code>CHARACTER</code> variable is declared with negative length.

</li><li> With <samp>-fopenmp</samp>, for fixed-form source code, when an <code>omx</code>
vendor-extension sentinel is encountered. (The equivalent <code>ompx</code>,
used in free-form source code, is diagnosed by default.)
</li></ul>

<a name="index-Wtabs"></a>
<a name="index-warnings_002c-tabs"></a>
<a name="index-tabulators"></a>
</dd>
<dt><code>-Wtabs</code></dt>
<dd><p>By default, tabs are accepted as whitespace, but tabs are not members
of the Fortran Character Set.  For continuation lines, a tab followed
by a digit between 1 and 9 is supported.  <samp>-Wtabs</samp> will cause a
warning to be issued if a tab is encountered. Note, <samp>-Wtabs</samp> is
active for <samp>-pedantic</samp>, <samp>-std=f95</samp>, <samp>-std=f2003</samp>,
<samp>-std=f2008</samp>, <samp>-std=f2018</samp> and
<samp>-Wall</samp>.
</p>
<a name="index-Wundefined_002ddo_002dloop"></a>
<a name="index-warnings_002c-undefined-do-loop"></a>
</dd>
<dt><code>-Wundefined-do-loop</code></dt>
<dd><p>Warn if a DO loop with step either 1 or -1 yields an underflow or an overflow
during iteration of an induction variable of the loop.
This option is implied by <samp>-Wall</samp>.
</p>
<a name="index-Wunderflow"></a>
<a name="index-warnings_002c-underflow"></a>
<a name="index-underflow"></a>
</dd>
<dt><code>-Wunderflow</code></dt>
<dd><p>Produce a warning when numerical constant expressions are
encountered, which yield an UNDERFLOW during compilation. Enabled by default.
</p>
<a name="index-Wintrinsic_002dshadow"></a>
<a name="index-warnings_002c-intrinsic"></a>
<a name="index-intrinsic"></a>
</dd>
<dt><code>-Wintrinsic-shadow</code></dt>
<dd><p>Warn if a user-defined procedure or module procedure has the same name as an
intrinsic; in this case, an explicit interface or <code>EXTERNAL</code> or
<code>INTRINSIC</code> declaration might be needed to get calls later resolved to
the desired intrinsic/procedure.  This option is implied by <samp>-Wall</samp>.
</p>
<a name="index-Wuse_002dwithout_002donly"></a>
<a name="index-warnings_002c-use-statements"></a>
<a name="index-intrinsic-1"></a>
</dd>
<dt><code>-Wuse-without-only</code></dt>
<dd><p>Warn if a <code>USE</code> statement has no <code>ONLY</code> qualifier and 
thus implicitly imports all public entities of the used module.
</p>
<a name="index-Wunused_002ddummy_002dargument"></a>
<a name="index-warnings_002c-unused-dummy-argument"></a>
<a name="index-unused-dummy-argument"></a>
<a name="index-dummy-argument_002c-unused"></a>
</dd>
<dt><code>-Wunused-dummy-argument</code></dt>
<dd><p>Warn about unused dummy arguments. This option is implied by <samp>-Wall</samp>.
</p>
<a name="index-Wunused_002dparameter"></a>
<a name="index-warnings_002c-unused-parameter"></a>
<a name="index-unused-parameter"></a>
</dd>
<dt><code>-Wunused-parameter</code></dt>
<dd><p>Contrary to <code>gcc</code>&rsquo;s meaning of <samp>-Wunused-parameter</samp>,
<code>gfortran</code>&rsquo;s implementation of this option does not warn
about unused dummy arguments (see <samp>-Wunused-dummy-argument</samp>),
but about unused <code>PARAMETER</code> values. <samp>-Wunused-parameter</samp>
is implied by <samp>-Wextra</samp> if also <samp>-Wunused</samp> or
<samp>-Wall</samp> is used.
</p>
<a name="index-Walign_002dcommons"></a>
<a name="index-warnings_002c-alignment-of-COMMON-blocks"></a>
<a name="index-alignment-of-COMMON-blocks"></a>
</dd>
<dt><code>-Walign-commons</code></dt>
<dd><p>By default, <code>gfortran</code> warns about any occasion of variables being
padded for proper alignment inside a <code>COMMON</code> block. This warning can be turned
off via <samp>-Wno-align-commons</samp>. See also <samp>-falign-commons</samp>.
</p>
<a name="index-Wfunction_002delimination"></a>
<a name="index-function-elimination"></a>
<a name="index-warnings_002c-function-elimination"></a>
</dd>
<dt><code>-Wfunction-elimination</code></dt>
<dd><p>Warn if any calls to impure functions are eliminated by the optimizations
enabled by the <samp>-ffrontend-optimize</samp> option.
This option is implied by <samp>-Wextra</samp>.
</p>
<a name="index-Wrealloc_002dlhs"></a>
<a name="index-Reallocate-the-LHS-in-assignments_002c-notification"></a>
</dd>
<dt><code>-Wrealloc-lhs</code></dt>
<dd><p>Warn when the compiler might insert code to for allocation or reallocation of
an allocatable array variable of intrinsic type in intrinsic assignments.  In
hot loops, the Fortran 2003 reallocation feature may reduce the performance.
If the array is already allocated with the correct shape, consider using a
whole-array array-spec (e.g. <code>(:,:,:)</code>) for the variable on the left-hand
side to prevent the reallocation check. Note that in some cases the warning
is shown, even if the compiler will optimize reallocation checks away.  For
instance, when the right-hand side contains the same variable multiplied by
a scalar.  See also <samp>-frealloc-lhs</samp>.
</p>
<a name="index-Wrealloc_002dlhs_002dall"></a>
</dd>
<dt><code>-Wrealloc-lhs-all</code></dt>
<dd><p>Warn when the compiler inserts code to for allocation or reallocation of an
allocatable variable; this includes scalars and derived types.
</p>
<a name="index-Wcompare_002dreals"></a>
</dd>
<dt><code>-Wcompare-reals</code></dt>
<dd><p>Warn when comparing real or complex types for equality or inequality.
This option is implied by <samp>-Wextra</samp>.
</p>
<a name="index-Wtargt_002dlifetime"></a>
</dd>
<dt><code>-Wtarget-lifetime</code></dt>
<dd><p>Warn if the pointer in a pointer assignment might be longer than the its
target. This option is implied by <samp>-Wall</samp>.
</p>
<a name="index-Wzerotrip"></a>
</dd>
<dt><code>-Wzerotrip</code></dt>
<dd><p>Warn if a <code>DO</code> loop is known to execute zero times at compile
time.  This option is implied by <samp>-Wall</samp>.
</p>
<a name="index-Wdo_002dsubscript"></a>
</dd>
<dt><code>-Wdo-subscript</code></dt>
<dd><p>Warn if an array subscript inside a DO loop could lead to an
out-of-bounds access even if the compiler cannot prove that the
statement is actually executed, in cases like
</p><div class="smallexample">
<pre class="smallexample">  real a(3)
  do i=1,4
    if (condition(i)) then
      a(i) = 1.2
    end if
  end do
</pre></div>
<p>This option is implied by <samp>-Wextra</samp>.
</p>
<a name="index-Werror"></a>
<a name="index-warnings_002c-to-errors"></a>
</dd>
<dt><code>-Werror</code></dt>
<dd><p>Turns all warnings into errors.
</p></dd>
</dl>

<p>See <a href="http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options">Options to Request or Suppress Errors and
Warnings</a> in <cite>Using the GNU Compiler Collection (GCC)</cite>, for information on
more options offered by the GBE shared by <code>gfortran</code>, <code>gcc</code>
and other GNU compilers.
</p>
<p>Some of these have no effect when compiling programs written in Fortran.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Debugging-Options.html#Debugging-Options" accesskey="n" rel="next">Debugging Options</a>, Previous: <a href="Preprocessing-Options.html#Preprocessing-Options" accesskey="p" rel="prev">Preprocessing Options</a>, Up: <a href="Invoking-GNU-Fortran.html#Invoking-GNU-Fortran" accesskey="u" rel="up">Invoking GNU Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
